/**
 * 
 */
package test.gm

import junit.framework.TestCase
import org.juiceshop.gm.*import org.juiceshop.gm.midi.Instrument

/**
 * @author JSTAUDEMEYER
 *
 */
public class NoteFactoryTest extends TestCase{

	NoteFactory nf
	Note n, n1, n2, n3, n4
	Phrase p, p1, p2, p3, p4
	
	void setUp() {
		nf = new NoteFactory()
	}
	
	void testNote() {
		nf.with {
	        n = note('C')
	        assertEquals 60, n.pitch      
	        assertEquals 60, C.pitch
	        assertEquals 62, D.pitch
		}
	}
	
	void testNoteWihKey() {
		nf.with {
            println current.key
            assertEquals "C-major",current.key.name
			assertEquals 65, F.pitch
			println F
			assertEquals 71, B.pitch
			println B
			current.key = G.major
            println current.key
            assertEquals "G-major",current.key.name
			assertEquals 66, F.pitch // F#
            println F
            assertEquals 71, B.pitch
            println B
            current.key = (F).major
            println current.key
            assertEquals "F-major",current.key.name
            assertEquals 65, F.pitch
            println F
            assertEquals 70, B.pitch
            println B
			current.key = C.major
            println current.key
            assertEquals "C-major",current.key.name
			assertEquals 65, F.pitch
            println F
			assertEquals 71, B.pitch
            println B
		}
	}
	
	void testRest() {
		nf.with {
			assertTrue rest().rest
			assertTrue R.rest
			assertEquals 1d, R.value
		}
	}
	
	void testPhrase() {
		nf.with {
			p = phrase(C,E,G)
			println p
			assertEquals 3, p.size()
			assertEquals 3d, p.value
			p = C|E|G|B
			println p
            assertEquals 4, p.size()
            assertEquals 4d, p.value
		}
		
	}
	
	void testInstrument() {
		nf.with {
			assertEquals Instrument.FLUTE, FLUTE
			assertEquals Instrument.BANJO, Instrument.valueOf('BANJO')
		}
	}
		
	void testInteger() {
		nf.with {
			n = C
			assertEquals 3, (3*n).size()
			assertEquals 6, (3*(C|E)).size()
			assertEquals 4, (4*(C%E)).size()
		}
	}

}
